home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume4 / savesrc < prev    next >
Encoding:
Text File  |  1986-11-30  |  32.6 KB  |  1,311 lines

  1. Newsgroups: mod.sources
  2. Subject: Two tools for organizing sources from USENET
  3. Approved: jpn@panda.UUCP
  4.  
  5. Mod.sources:  Volume 4, Issue 77
  6. Submitted by: decvax!utzoo!toram!chris
  7.  
  8. #! /bin/sh
  9. # This is a shell archive, meaning:
  10. # 1. Remove everything above the #! /bin/sh line.
  11. # 2. Save the resulting text in a file.
  12. # 3. Execute the file with /bin/sh (not csh) to create the files:
  13. #    README
  14. #    note
  15. #    note.1
  16. #    savesrc
  17. #    savesrc.1
  18. # This archive created: Fri Apr 25 06:58:31 1986
  19. export PATH; PATH=/bin:$PATH
  20. echo shar: extracting "'README'" '(1027 characters)'
  21. if test -f 'README'
  22. then
  23.     echo shar: will not over-write existing file "'README'"
  24. else
  25. cat << \SHAR_EOF > 'README'
  26.     Here are two shell programs, "saversc" and "note" (plus manual pages),
  27. for organizing sources from Usenet.  I wrote them to deal sensibly with my
  28. ever-growing "miscellaneous net sources" directory, and have found them
  29. enormously useful.  I expect other folks will find them helpful too.
  30.  
  31. Basically, "savesrc" will take a single program source file or a
  32. shell archive, place it in a designated source directory or sub-directory
  33. thereof, unshar it if necessary, generate a Makefile entry if necessary,
  34. prompt for a half-line description of what the program does, attempt
  35. to compile it, give the user a shell to twiddle it when it doesn't
  36. work, and add entries to a file of notes indicating what it is, where
  37. and whom it came from, when it arrived, and whether or not it works.
  38. It will also deal sensibly with header files, bugs/fixes, and manual pages.
  39. It can be used directly from "rn" as "| savesrc destination".
  40.  
  41. "Note" manages the files of notes on the sources.
  42.  
  43.     Christine Robertson  {ihnp4,linus,decvax}!utzoo!toram!chris
  44. SHAR_EOF
  45. if test 1027 -ne "`wc -c < 'README'`"
  46. then
  47.     echo shar: error transmitting "'README'" '(should have been 1027 characters)'
  48. fi
  49. fi
  50. echo shar: extracting "'note'" '(2285 characters)'
  51. if test -f 'note'
  52. then
  53.     echo shar: will not over-write existing file "'note'"
  54. else
  55. cat << \SHAR_EOF > 'note'
  56. #!/bin/sh
  57. #
  58. #    Note:     manage notes on program sources
  59. #
  60. #             Copyright (c) Chris Robertson 1985
  61. #
  62. #    This script adds lines from standard input to a file called NOTES
  63. #    in the current directory, or views/edits the file.  It is intended
  64. #    for keeping notes on software slurped from the net.
  65. #    The format of NOTES is:
  66. #    
  67. #    progname:    [date] comments ...
  68. #    (1 tab)    more comments
  69. #    (blank line)
  70. #
  71. #    Usage:  note [-e] [-s] [-r [program ...]]
  72. #
  73. #    No options:        add a NOTE.
  74. #    -e:                edit the NOTES file.
  75. #    -r:                show all notes on the given program(s), or the entire
  76. #                    NOTES file (unsorted) if no program is given.
  77. #    -s:                show the entire NOTES file, sorted so all notes on a
  78. #                    given program occur together.
  79. #
  80.  
  81. PAGER=${PAGER-/usr/local/bin/more}
  82. case "$PAGER" in
  83.     "")                        # in case it's explicitly set to nothing
  84.         PAGER=cat
  85.         ;;
  86. esac
  87.  
  88. case "$VISUAL" in
  89.     "")
  90.         case "$EDITOR" in
  91.             "")
  92.                 ;;
  93.             *)
  94.                 VISUAL=$EDITOR
  95.                 ;;
  96.         esac
  97.         ;;
  98. esac
  99. VISUAL=${VISUAL-/usr/bin/vi}
  100. case "$VISUAL" in
  101.     "")                        # in case it's explicitly set to nothing
  102.         VISUAL=/bin/ed
  103.         ;;
  104. esac
  105.  
  106. trap "rm -f /tmp/note$$;exit" 0 1 2 3
  107.  
  108. # find which echo we're using
  109.  
  110. case "`echo -n foo`" in
  111.     -n*)
  112.         c="\c"
  113.         n=""
  114.         ;;
  115.     foo)
  116.         c=""
  117.         n="-n"
  118.         ;;
  119.     *)
  120.         echo "Your echo command is broken!"
  121.         c=
  122.         n=
  123.         ;;
  124. esac
  125.  
  126. usage="Usage: $0 [-e] [-s] [-r [prog ...]]"
  127.  
  128. case "$#" in
  129.     0)
  130.         ;;
  131.     1)
  132.         case "$1" in
  133.             -r)
  134.                 $PAGER NOTES
  135.                 exit 0
  136.                 ;;
  137.             -s)
  138.                 list="`sed -e '/^    /d' -e 's/:.*//' NOTES | sort -u`"
  139.                 for i in $list
  140.                     do
  141.                     note -r $i >> /tmp/note$$
  142.                 done
  143.                 $PAGER /tmp/note$$
  144.                 rm -f /tmp/note$$
  145.                 exit 0
  146.                 ;;
  147.             -e)
  148.                 $VISUAL NOTES
  149.                 exit 0
  150.                 ;;
  151.             *)
  152.                 echo $usage
  153.                 exit 1
  154.                 ;;
  155.         esac
  156.         ;;
  157.     *)
  158.         case "$1" in
  159.             -r)
  160.                 shift
  161.                 for prog in $*
  162.                     do
  163.                     case "$PAGER" in
  164.                         *cat)
  165.                             sed -n -e "/^${prog}:/,/^\$/p" NOTES
  166.                             ;;
  167.                         *)
  168.                             sed -n -e "/^${prog}:/,/^\$/p" NOTES | $PAGER
  169.                             ;;
  170.                     esac
  171.                 done
  172.                 exit 0
  173.                 ;;
  174.             *)
  175.                 echo $usage
  176.                 exit 1
  177.                 ;;
  178.         esac
  179.         ;;
  180. esac
  181. date="`set - \`date\`;echo $2 $3 $6`"
  182. echo $n "Program name: $c"
  183. read prog
  184. echo $n "> $c"
  185. read line
  186. echo "${prog}:    [$date] $line" >> NOTES
  187. line=
  188. while :
  189.     do
  190.     echo $n "> $c"
  191.     read line
  192.     case "$line" in
  193.         .)
  194.             break
  195.             ;;
  196.     esac
  197.     echo "    $line" >> NOTES
  198. done
  199. echo "" >> NOTES
  200. SHAR_EOF
  201. if test 2285 -ne "`wc -c < 'note'`"
  202. then
  203.     echo shar: error transmitting "'note'" '(should have been 2285 characters)'
  204. fi
  205. fi
  206. echo shar: extracting "'note.1'" '(1623 characters)'
  207. if test -f 'note.1'
  208. then
  209.     echo shar: will not over-write existing file "'note.1'"
  210. else
  211. cat << \SHAR_EOF > 'note.1'
  212. .ls 1
  213. .TH NOTE 1 LOCAL
  214. .SH NAME
  215. note \- manage notes on program sources
  216. .SH SYNOPSIS
  217. \fBnote\fR [\fB\-e\fR] [\fB\-s\fR] [\fB\-r\fR [program ...]]
  218. .SH DESCRIPTION
  219. \fINote\fR is a shell script designed to manage notes on sources, such
  220. as what they are, where and whom they came from, when they were
  221. received/created, and whether or not they work.
  222. It is primarily intended for keeping track of software recived via
  223. the Usenet news network.
  224. .sp
  225. With no options, \fInote\fR appends lines from standard input
  226. to a file called ``NOTES'' in the current directory. 
  227. The format of a NOTES file is:
  228. .sp
  229. .nf
  230. .in +0.7i
  231. .ta 0.8i
  232. program:    [Mmm dd yy] comments ...
  233. <\fI1 tab\fR>    more comments
  234. <\fIblank line\fR>
  235. .sp
  236. .fi
  237. .in -0.7i
  238. .TP
  239. \fB\-e\fR    edit the NOTES file using $VISUAL as the editor.
  240. If VISUAL is not set, \fInote\fR looks for $EDITOR, and if that is
  241. also not set, defaults to ``/usr/bin/vi''.
  242. .TP
  243. \fB\-r\fR    show all notes on the given program(s), or the entire NOTES
  244. file (unsorted) if no program is given, piped through $PAGER (unless
  245. PAGER is \fIcat\fR).
  246. .TP
  247. \fB\-s\fR    show the entire NOTES file, sorted so all notes on a
  248. given program occur together, piped through $PAGER.
  249. .SH ENVIRONMENT VARIABLES
  250. .ta 1.3i 3i
  251. .nf
  252. \fBName    Default    Purpose\fR
  253. .sp
  254. PAGER    /usr/local/bin/more    Used to page output
  255. VISUAL    /usr/bin/vi    Used to edit the NOTES file
  256. EDITOR    none    Used if VISUAL is not set
  257. .fi
  258. .SH FILES
  259. .ta 1.3i
  260. ./NOTES    file where notes are kept
  261. .br
  262. /tmp/note$$    temporary files
  263. .SH SEE ALSO
  264. \fIsavesrc(1L)\fR
  265. .SH AUTHOR
  266. Written by Christine Robertson 1986
  267. .SH BUGS
  268. Please send all bug reports to {linus, ihnp4, decvax}!utzoo!toram!chris.
  269. SHAR_EOF
  270. if test 1623 -ne "`wc -c < 'note.1'`"
  271. then
  272.     echo shar: error transmitting "'note.1'" '(should have been 1623 characters)'
  273. fi
  274. fi
  275. echo shar: extracting "'savesrc'" '(14268 characters)'
  276. if test -f 'savesrc'
  277. then
  278.     echo shar: will not over-write existing file "'savesrc'"
  279. else
  280. cat << \SHAR_EOF > 'savesrc'
  281. #!/bin/sh
  282.  
  283. #
  284. #    Savesrc:    Unpack program sources from news in a sensible manner.
  285. #
  286. #                Copyright (c) Chris Robertson 1986
  287. #
  288. #    Savesrc will put a C source file into a default sources
  289. #    directory, or make a new directory (subdirectory by default) for
  290. #    a shar-ed source and unpack it.  It will make an entry
  291. #    in a Makefile (or a whole basic Makefile, if necessary),
  292. #    take a shot at compiling the thing if you want it to, give
  293. #    you a shell to diddle the source when it won't compile, prompt
  294. #    you for a short blurb about what it does, and create a note
  295. #    as to where it came from and when, and whether it compiles
  296. #    and works, so you have some chance of remembering what state this
  297. #    stuff is in next time you look at it.  A simple auxilliary program,
  298. #    note, goes with this and is used for adding/reading notes on
  299. #    sources.  Prompts are deliberately rather terse for those folks who
  300. #    read news at slow baud rates.
  301. #
  302. #    Usage:    from rn, | savesrc dest
  303. #            otherwise, savesrc dest [sourcefile ... ]
  304. #
  305. #    Savesrc expects at least one argument, the name of a C source file
  306. #    (in "foo.c" form), or the name of a directory to put a bunch
  307. #    of stuff in, and may have several other arguments which are
  308. #    used as the program source input files.  It is normally not
  309. #    very sensible to give it more than one source file, however.
  310. #
  311. #    Use QUIT to abort it, not DEL.
  312. #
  313. #    Assumptions:
  314. #        /bin/[ exists -- replace with "test" if necessary
  315. #        unshar exists -- replace with "sh" if necessary
  316. #        note exists   -- replace with "cat >> NOTES" if necessary
  317. #
  318. #    Editing Note:
  319. #        This is set up for vi with tabstop=4 and shiftwidth=4.
  320. #        Indenting will look funny otherwise.
  321. #
  322.  
  323. trap '' 2
  324. trap "rm -f /tmp/newsrc$$;exit" 0 1 3
  325.  
  326. case "$VISUAL" in
  327.     "")
  328.         case "$EDITOR" in
  329.             "")
  330.                 ;;
  331.             *)
  332.                 VISUAL=$EDITOR
  333.                 ;;
  334.         esac
  335.         ;;
  336. esac
  337. VISUAL=${VISUAL-/usr/bin/vi}
  338. case "$VISUAL" in
  339.     "")                        # in case it's explicitly set to nothing
  340.         VISUAL=/bin/ed
  341.         ;;
  342. esac
  343. SHELL=${SHELL-/bin/sh}
  344. PAGER=${PAGER-/usr/local/bin/more}
  345. case "$PAGER" in
  346.     "")                        # in case it's explicitly set to nothing
  347.         PAGER=cat
  348.         ;;
  349. esac
  350.  
  351. srcdir=${srcdir-$HOME/src}                # where source is kept -- overidden by
  352.                                         #    a full pathname for dest
  353. mandir=${mandir-$HOME/man}                # where src manual pages go
  354. catdir=${catdir-$HOME/man}                # where formatted manual pages go
  355. CFLAGS=${CFLAGS--O}                        # used in generating a Makefile
  356.  
  357. ls="ls -F"                                # replace with your favourite
  358.  
  359. # find which echo we're using, thanks to Larry Wall for the idea
  360.  
  361. case "`echo -n foo`" in
  362.     -n*)
  363.         c="\c"
  364.         n=""
  365.         ;;
  366.     foo)
  367.         c=""
  368.         n="-n"
  369.         ;;
  370.     *)
  371.         echo "Your echo command is broken!"
  372.         c=
  373.         n=
  374.         ;;
  375. esac
  376.  
  377. # find what we want to call it and save the article (read standard input
  378. # if no filename given)
  379.  
  380. case "$#" in
  381.     0)
  382.         echo "Usage: savesrc dest [sourcefile ...]" > /dev/tty
  383.         exit 1
  384.         ;;
  385. esac
  386. dest=$1
  387. shift
  388. cat $* > /tmp/newsrc$$
  389.  
  390. # if what we've saved was a news article, strip off the header, but
  391. # remember the date, path, and poster.  If you have 'bm', you may want
  392. # to replace 'grep' with it for speed.
  393.  
  394. date="`set - \`date\`;echo $2 $3 $6`"
  395. case "`egrep 'Posting-Version|Relay-Version:|^From:' /tmp/newsrc$$`" in
  396.     "")
  397.         # not a news article
  398.  
  399.         path=
  400.         poster=
  401.         ;;
  402.     *)
  403.         path="`grep '^Path:' /tmp/newsrc$$`"
  404.         poster="`grep '^From:' /tmp/newsrc$$`"
  405.         sed -e '1,/^$/d' /tmp/newsrc$$ > /tmp/strip$$
  406.         mv /tmp/strip$$ /tmp/newsrc$$
  407.         ;;
  408. esac
  409.  
  410. # set up standard input and output to be /dev/tty, in case this is invoked
  411. # via a pipe from rn
  412.  
  413. exec < /dev/tty > /dev/tty
  414.  
  415. # see if we got a full pathname as 'dest', otherwise cd to source dir
  416.  
  417. case "$dest" in
  418.     /*)
  419.         ;;
  420.     *)
  421.         cd $srcdir || exit 0
  422.         ;;
  423. esac
  424.  
  425. # file names known about are *.?, *.[1-8], *.fix, *.bug, *.patch, & READ* --
  426. # anything else is assumed to be a directory name 
  427.  
  428. case "$dest" in
  429.     *.[1-8])                     # manual pages
  430.         until [ ! -s "$dest" ]
  431.             do
  432.             echo $n "\nOverwrite '$dest'? [n] $c"
  433.             read answer
  434.             case "$answer" in
  435.                 q*|Q*)
  436.                     exit 0
  437.                     ;;
  438.                 y*|Y*)
  439.                     break
  440.                     ;;
  441.                 *)
  442.                     echo $n "New name: $c"
  443.                     read dest
  444.                     ;;
  445.             esac
  446.         done
  447.         mv /tmp/newsrc$$ $dest
  448.         echo $n "\nEdit ${dest}? [y] $c"
  449.         read answer
  450.         case "$answer" in
  451.             q*|Q*)
  452.                 exit 0
  453.                 ;;
  454.             n*|N*)
  455.                 ;;
  456.             *)
  457.                 trap '' 2 3
  458.                 ($VISUAL $dest)
  459.                 trap 3
  460.                 ;;
  461.         esac
  462.         section=`expr "$dest" : '.*\.\(.*\)'`
  463.         case "`file $dest`" in
  464.             *roff*)
  465.                 echo $n "\n$dest -- man page source. Move to $mandir/man${section}? [y] $c"
  466.                 read answer
  467.                 case "$answer" in
  468.                     q*|Q*)
  469.                         exit 0
  470.                         ;;
  471.                     n*|N*)
  472.                         ;;
  473.                     *)
  474.                         if [ ! -d $mandir/man$section ]
  475.                             then
  476.                             if (mkdir $mandir/man$section > /dev/null 2>&1)
  477.                                 then
  478.                                 mv $dest $mandir/man$section
  479.                                 dest=$mandir/man$section/$dest
  480.                             else
  481.                                 echo "Can't make directory $mandir/man$section -- can't move $dest."
  482.                             fi
  483.                         else
  484.                             mv $dest $mandir/man$section
  485.                             dest=$mandir/man$section/$dest
  486.                         fi
  487.                         ;;
  488.                 esac
  489.                 echo $n "\nNroff it to $catdir/cat${section}? [y] $c"
  490.                 read answer
  491.                 case "$answer" in
  492.                     q*|Q*)
  493.                         exit 0
  494.                         ;;
  495.                     n*|N*)
  496.                         ;;
  497.                     *)
  498.                         if [ ! -d $catdir/cat$section ]
  499.                             then
  500.                             if (mkdir $catdir/cat$section > /dev/null 2>&1)
  501.                                 then
  502.                                 nroff -man $dest > $catdir/cat$section/$dest
  503.                                 $PAGER $catdir/cat$section/$dest
  504.                             else
  505.                                 echo "Can't make directory $catdir/cat$section -- can't nroff $dest."
  506.                             fi
  507.                         else
  508.                             nroff -man $dest > $catdir/cat$section/`basename $dest`
  509.                             $PAGER $catdir/cat$section/`basename $dest`
  510.                         fi
  511.                         ;;
  512.                 esac
  513.                 ;;
  514.             *)
  515.                 echo $n "\nMove $dest to $catdir/cat${section}? [y] $c"
  516.                 read answer
  517.                 case "$answer" in
  518.                     q*|Q*)
  519.                         exit 0
  520.                         ;;
  521.                     n*|N*)
  522.                         ;;
  523.                     *)
  524.                         if [ ! -d $catdir/cat$section ]
  525.                             then
  526.                             if (mkdir $catdir/cat$section > /dev/null 2>&1)
  527.                                 then
  528.                                 mv $dest $catdir/cat$section/$dest
  529.                             else
  530.                                 echo "Can't make directory $catdir/cat$section -- can't move $dest."
  531.                             fi
  532.                         fi
  533.                         ;;
  534.                 esac
  535.                 ;;
  536.         esac
  537.         ;;
  538.     READ*|*.?|*.fix|*.bug|*.patch)
  539.         # we are dealing with a single, (relatively!) short program
  540.  
  541.         copy=yes
  542.         until [ ! -s "$dest" ]
  543.             do
  544.             echo $n "\nOverwrite '$dest'? [n] $c"
  545.             read answer
  546.             case "$answer" in
  547.                 q*|Q*)
  548.                     exit 0
  549.                     ;;
  550.                 y*|Y*)
  551.                     break
  552.                     ;;
  553.                 *)
  554.                     echo $n "Append to '$dest'? [n] $c"
  555.                     read answer
  556.                     case "$answer" in
  557.                         q*|Q*)
  558.                             exit 0
  559.                             ;;
  560.                         y*|y*)
  561.                             cat /tmp/newsrc$$ >> $dest
  562.                             copy=no
  563.                             ;;
  564.                         *)
  565.                             echo $n "New name: $c"
  566.                             read dest
  567.                             ;;
  568.                     esac
  569.                     ;;
  570.             esac
  571.         done
  572.         case "$copy" in
  573.             yes)
  574.                 cp /tmp/newsrc$$ $dest
  575.                 ;;
  576.         esac
  577.         echo $n "\nEdit ${dest}? [y] $c"
  578.         read answer
  579.         case "$answer" in
  580.             q*|Q*)
  581.                 exit 0
  582.                 ;;
  583.             n*|N*)
  584.                 echo $n "Want a shell? [y] $c"
  585.                 read answer
  586.                 case "$answer" in
  587.                     q*|Q*)
  588.                         exit 0
  589.                         ;;
  590.                     n*|N*)
  591.                         ;;
  592.                     *)
  593.                         $SHELL
  594.                         ;;
  595.                 esac
  596.                 ;;
  597.             *)
  598.                 trap '' 2 3
  599.                 ($VISUAL $dest)
  600.                 trap 3
  601.                 ;;
  602.         esac
  603.         case "$dest" in
  604.             READ*|*.h)
  605.                 exit 0
  606.                 ;;
  607.             *.fix|*.bug|*.patch)
  608.                 echo $n "Want a shell? [y] $c"
  609.                 read answer
  610.                 case "$answer" in
  611.                     q*|Q*)
  612.                         exit 0
  613.                         ;;
  614.                     n*|N*)
  615.                         ;;
  616.                     *)
  617.                         $SHELL
  618.                         ;;
  619.                 esac
  620.                 exit 0
  621.                 ;;
  622.         esac
  623.  
  624.         # set up a summary for later use
  625.  
  626.         echo $n "\n1/2-line program summary: $c"
  627.         read blurb
  628.  
  629.         # if "makefile" exists, add it to "Makefile", for consistency
  630.  
  631.         if [ -s "makefile" ]
  632.             then
  633.             cat makefile >> Makefile
  634.             rm makefile
  635.             ed - Makefile << ++++
  636.             g/makefile/s//Makefile/g
  637.             w
  638. ++++
  639.         fi
  640.  
  641.         # add a Makefile entry if there isn't one there already
  642.  
  643.         bname=`basename $dest .c`
  644.         case "`grep \"^${bname}:    \" Makefile`" in
  645.             "")
  646.                 echo $n "Want a Makefile entry? [y] $c"
  647.                 read answer
  648.                 case "$answer" in
  649.                     q*|Q*)
  650.                         exit 0
  651.                         ;;
  652.                     n*|N*)
  653.                         ;;
  654.                     *)
  655.                         echo "\n# $bname -- $blurb\n" >> Makefile
  656.                         echo "Default:\n\n$bname: $bname.o\n    cc \$(CFLAGS) $bname.o -o $bname"
  657.                         echo $n "\nOK as the Makefile entry? [y] $c"
  658.                         read answer
  659.                         case "$answer" in
  660.                             q*|Q*)
  661.                                 exit 0
  662.                                 ;;
  663.                             y*|Y*|"")
  664.                                 echo "$bname: $bname.o" >> Makefile
  665.                                 echo "    cc \$(CFLAGS) $bname.o -o $bname" >> Makefile
  666.                                 ;;
  667.                             *)
  668.                                 echo $n "\nComplete Makefile entry (. to end)\n> $c"
  669.                                 read instruct
  670.                                 echo "$instruct" >> Makefile
  671.                                 instruct=
  672.                                 while :
  673.                                     do
  674.                                     echo $n "> $c"
  675.                                     read instruct
  676.                                     case "$instruct" in
  677.                                         .)
  678.                                             break
  679.                                             ;;
  680.                                     esac
  681.                                     echo "    $instruct" >> Makefile    # tab is essential
  682.                                 done
  683.                                 ;;
  684.                         esac
  685.                         ;;
  686.                 esac
  687.                 ;;
  688.         esac
  689.         ;;
  690.     *)
  691.         # we are probably going to make a new directory for this one
  692.  
  693.         newdir=true
  694.         if [ -d "$dest" ]
  695.             then
  696.             echo $n "\n$dest already exists -- put the stuff there? [y] $c"
  697.             read answer
  698.             case "$answer" in
  699.                 q*|Q*)
  700.                     exit 0
  701.                     ;;
  702.                 n*|N*)
  703.                     echo $n "New directory name: $c"
  704.                     read dest
  705.                     ;;
  706.                 *)
  707.                     newdir=false
  708.                     ;;
  709.             esac
  710.         fi
  711.         if ($newdir)
  712.             then
  713.             until ( mkdir "$dest" > /dev/null 2>&1 )
  714.                 do
  715.                 echo $n "Can't make '$dest'.\nNew name: $c"
  716.                 read dest
  717.             done
  718.         fi
  719.  
  720.         cd $dest || exit 1
  721.  
  722.         # set up a summary for later use
  723.  
  724.         echo $n "\n1/2-line program description: $c"
  725.         read blurb
  726.  
  727.         echo $n "\nUnshar it? [y] $c"
  728.         read answer
  729.         case "$answer" in
  730.             q*|Q*)
  731.                 exit 0
  732.                 ;;
  733.             n*|N*)
  734.                 echo $n "\nEdit it? [y] $c"
  735.                 read answer
  736.                 case "$answer" in
  737.                     q*|Q*)
  738.                         exit 0
  739.                         ;;
  740.                     n*|N*)
  741.                         echo $n "Want a shell? [y] $c"
  742.                         read answer
  743.                         case "$answer" in
  744.                             q*|Q*)
  745.                                 exit 0
  746.                                 ;;
  747.                             n*|N*)
  748.                                 ;;
  749.                             *)
  750.                                 $SHELL
  751.                                 ;;
  752.                         esac
  753.                         ;;
  754.                     *)
  755.                         trap '' 2 3
  756.                         ($VISUAL /tmp/newsrc$$)
  757.                         trap 3
  758.                         ;;
  759.                 esac
  760.                 $ls
  761.                 echo $n "\ncp /tmp/newsrc$$ what? [RETURN = no copy] $c"
  762.                 read name
  763.                 case "$name" in
  764.                     "")
  765.                         ;;
  766.                     *)
  767.                         cp /tmp/newsrc$$ $name
  768.                         ;;
  769.                 esac
  770.                 ;;
  771.             *)
  772.                 unshar /tmp/newsrc$$
  773.                 $ls
  774.                 echo $n "\nDid that extract OK? [y] $c"
  775.                 read answer
  776.                 case "$answer" in
  777.                     q*|Q*)
  778.                         exit 0
  779.                         ;;
  780.                     n*|N*)
  781.                         echo "Starting a shell."
  782.                         trap '' 2 3
  783.                         ($SHELL)
  784.                         trap 3
  785.                         $ls
  786.                         echo $n "\ncp /tmp/newsrc$$ what? [RETURN = no copy] $c"
  787.                         read name
  788.                         case "$name" in
  789.                             "")
  790.                                 ;;
  791.                             *)
  792.                                 cp /tmp/newsrc$$ $name
  793.                                 ;;
  794.                         esac
  795.                         ;;
  796.                 esac
  797.                 ;;
  798.         esac
  799.         if [ -s "README" -o -s "READ_ME" ]
  800.             then
  801.             echo $n "\nSee the README? [y] $c"
  802.             read answer
  803.             case "$answer" in
  804.                 q*|Q*)
  805.                     exit 0
  806.                     ;;
  807.                 n*|N*)
  808.                     ;;
  809.                 *)
  810.                     $PAGER READ*
  811.                     ;;
  812.             esac
  813.         else
  814.             echo $n "\nEdit a README? [y] $c"
  815.             read answer
  816.             case "$answer" in
  817.                 q*|Q*)
  818.                     exit 0
  819.                     ;;
  820.                 n*|N*)
  821.                     ;;
  822.                 *)
  823.                     trap '' 2 3
  824.                     ($VISUAL README)
  825.                     trap 3
  826.                     ;;
  827.             esac
  828.         fi
  829.  
  830.         # manual pages
  831.  
  832.         for i in `ls *.[1-8] 2> /dev/null`
  833.             do
  834.             page=$i
  835.             case "`file $i`" in
  836.                 *roff*)
  837.                     section=`expr "$i" : '.*\.\(.*\)'`
  838.                     echo $n "\n$i -- man page source. Copy to $mandir/man${section}? [y] $c"
  839.                     read answer
  840.                     case "$answer" in
  841.                         q*|Q*)
  842.                             exit 0
  843.                             ;;
  844.                         n*|N*)
  845.                             ;;
  846.                         *)
  847.                             if [ ! -d $mandir/man$section ]
  848.                                 then
  849.                                 if (mkdir $mandir/man$section > /dev/null 2>&1)
  850.                                     then
  851.                                     cp $i $mandir/man$section
  852.                                     page=$mandir/man$section/$i
  853.                                 else
  854.                                     echo "Can't make directory $mandir/man$section -- can't move $dest."
  855.                                 fi
  856.                             else
  857.                                 cp $i $mandir/man$section
  858.                                 page=$mandir/man$section/$i
  859.                             fi
  860.                             ;;
  861.                     esac
  862.                     echo $n "\nNroff it to $catdir/cat${section}? [y] $c"
  863.                     read answer
  864.                     case "$answer" in
  865.                         q*|Q*)
  866.                             exit 0
  867.                             ;;
  868.                         n*|N*)
  869.                             ;;
  870.                         *)
  871.                             if [ ! -d $catdir/cat$section ]
  872.                                 then
  873.                                 if (mkdir $catdir/cat$section > /dev/null 2>&1)
  874.                                     then
  875.                                     nroff -man $page > $catdir/cat$section/$i
  876.                                     $PAGER $catdir/cat$section/$i
  877.                                 else
  878.                                     echo "Can't make directory $catdir/cat$section -- can't nroff $dest."
  879.                                 fi
  880.                             else
  881.                                 nroff -man $page > $catdir/cat$section/$i
  882.                                 $PAGER $catdir/cat$section/$i
  883.                             fi
  884.                             ;;
  885.                     esac
  886.                     ;;
  887.             esac
  888.         done
  889.  
  890.         # if "makefile" exists, move it to "Makefile", for consistency
  891.  
  892.         if [ -s "makefile" ]
  893.             then
  894.             cat makefile >> Makefile
  895.             rm makefile
  896.             ed - Makefile << ++++
  897.             g/makefile/s//Makefile/g
  898.             w
  899. ++++
  900.         fi
  901.         if [ ! -s "Makefile" ]
  902.             then
  903.             echo $n "\nGot a Makefile somewhere? [n] $c"
  904.             read answer
  905.             case "$answer" in
  906.                 q*|Q*)
  907.                     exit 0
  908.                     ;;
  909.                 y*|y*)
  910.                     echo $n "What's it called? $c"
  911.                     read name
  912.                     cp $name Makefile
  913.                     ;;
  914.                 *)
  915.                     echo $n "Generating basic Makefile ... $c"
  916.                     echo "# $dest -- $blurb\n" > Makefile
  917.                     echo $n "\nCFILES =    $c" >> Makefile
  918.                     for i in `ls *.c 2> /dev/null`
  919.                         do
  920.                         echo $n "$i $c" >> Makefile
  921.                     done
  922.                     echo $n "\n\nOFILES =    $c" >> Makefile
  923.                     for i in `ls *.c 2> /dev/null`
  924.                         do
  925.                         echo $n "`basename $i .c`.o $c" >> Makefile
  926.                     done
  927.                     echo "\n\nCFLAGS =    $CFLAGS" >> Makefile
  928.                     echo "\n${dest}:    \$(OFILES)" >> Makefile
  929.                     echo "    cc \$(CFLAGS) \$(OFILES) -o $dest" >> Makefile
  930.                     echo "\nclean:\n    rm -f *.o" >> Makefile
  931.  
  932.                     echo "Done."
  933.                     ;;
  934.             esac
  935.         fi
  936.         ;;
  937. esac
  938.  
  939. echo $n "\nEdit Makefile? [y] $c"
  940. read answer
  941. case "$answer" in
  942.     q*|Q*)
  943.         exit 0
  944.         ;;
  945.     n*|N*)
  946.         ;;
  947.     *)
  948.         trap '' 2 3
  949.         ($VISUAL Makefile)
  950.         trap 3
  951.         ;;
  952. esac
  953.  
  954. # create basic NOTES entry for it
  955.  
  956. echo $n "\nCreate basic NOTES entry? [y] $c"
  957. read answer
  958. case "$answer" in
  959.     q*|Q*)
  960.         exit 0
  961.         ;;
  962.     n*|N*)
  963.         ;;
  964.     *)
  965.         echo "`basename $dest .c`:    [$date] ${blurb}" >> NOTES
  966.         case "$poster" in
  967.             "")                        # not a net article
  968.                 ;;
  969.             *)
  970.                 echo "    $poster" >> NOTES
  971.                 echo "    $path" >> NOTES
  972.                 ;;
  973.         esac
  974.         echo "" >> NOTES
  975.         ;;
  976. esac
  977.  
  978. echo $n "\nCompile ${dest}? [y] $c"
  979. read answer
  980. case "$answer" in
  981.     q*|Q*)
  982.         exit 0
  983.         ;;
  984.     n*|N*)
  985.         ;;
  986.     *)
  987.         make $bname
  988.         ;;
  989. esac
  990. echo $n "\nWant a shell? [y] $c"
  991. read answer
  992. case "$answer" in
  993.     q*|Q*)
  994.         exit 0
  995.         ;;
  996.     n*|N*)
  997.         ;;
  998.     *)
  999.         trap '' 2 3
  1000.         ($SHELL)
  1001.         trap 3
  1002.         ;;
  1003. esac
  1004. echo $n "\nAny NOTES? [y] $c"
  1005. read answer
  1006. case "$answer" in
  1007.     q*|Q*)
  1008.         exit 0
  1009.         ;;
  1010.     n*|N*)
  1011.         ;;
  1012.     *)
  1013.         note
  1014.         ;;
  1015. esac
  1016. SHAR_EOF
  1017. if test 14268 -ne "`wc -c < 'savesrc'`"
  1018. then
  1019.     echo shar: error transmitting "'savesrc'" '(should have been 14268 characters)'
  1020. fi
  1021. fi
  1022. echo shar: extracting "'savesrc.1'" '(12044 characters)'
  1023. if test -f 'savesrc.1'
  1024. then
  1025.     echo shar: will not over-write existing file "'savesrc.1'"
  1026. else
  1027. sed 's/^X//' << \SHAR_EOF > 'savesrc.1'
  1028. .ls 1
  1029. .vs 11.5
  1030. .TH SAVESRC 1 LOCAL
  1031. .SH NAME
  1032. savesrc \- organize program sources from Usenet
  1033. .SH SYNOPSIS
  1034. \fBsavesrc\fR destination [source file ...]
  1035. .SH DESCRIPTION
  1036. \fISavesrc\fR is a shell program designed to simplify the retrieval,
  1037. testing, documentation,
  1038. and storage of program sources from the Usenet news network, although it
  1039. can be used with any source files.
  1040. .sp 0.13i
  1041. \fISavesrc\fR will read standard input if no source files are given, so
  1042. a news article may be piped to it conveniently from newsreaders with this
  1043. facility, such as \fIrn(1)\fR.
  1044. This makes it much easier to save sources in a standard manner
  1045. and test them out while actually reading news, rather than accumulating
  1046. messy directories of miscellaneous sources to be organized Real Soon Now.
  1047. .sp 0.13i
  1048. Basically, \fIsavesrc\fR will take a single program source file or a
  1049. shell archive, place it in a designated source directory or sub-directory
  1050. thereof, unshar it if necessary, generate a Makefile entry if necessary,
  1051. prompt for a half-line description of what the program does, attempt
  1052. to compile it, give the user a shell to twiddle it when it doesn't
  1053. work, and add entries to a file of notes indicating what it is, where
  1054. and who it came from, when it arrived, and whether or not it works.
  1055. It will also deal sensibly with header files and manual pages.
  1056. .sp 0.13i
  1057. \fISavesrc\fR is interactive.
  1058. It may be terminated by typing ``q'' in response to any question, but
  1059. cannot be aborted with an interrupt.
  1060. If panic stikes, \fIquit\fR (normally CTRL-\e) will produce a graceful exit.
  1061. .sp 0.2i
  1062. \fBDirectory Structures Etc.\fR
  1063. .sp 0.13i
  1064. \fISavesrc\fR assumes that all sources will be placed in a \fImain
  1065. sources directory\fR, or in sub-directories under it.
  1066. It will look for an environment variable ``srcdir'' giving the
  1067. full pathname of this directory;  the default value is ``$HOME/src''.
  1068. .sp 0.13i
  1069. Manual page sources are assumed to live in a directory with
  1070. subdirectories named ``man1'' through ``man8'', and manual pages
  1071. which have been formatted using \fInroff -man\fR are assumed to live in a
  1072. directory with subdirectories named ``cat1'' through ``cat8''.
  1073. \fISavesrc\fR looks for two environment variables, ``mandir''
  1074. and ``catdir'', which give the full pathnames of these directories.
  1075. ``Mandir'' and ``catdir'' may be the same;  the default value for each
  1076. is ``$HOME/man''.
  1077. .sp 0.13i
  1078. \fISavesrc\fR further assumes that there will be a Makefile in the main sources
  1079. directory;  one will be created if it does not exist.
  1080. Incidentally, if a ``makefile'' is found anywhere, it is appended to
  1081. ``Makefile'' and then removed, in the interests of consistency.
  1082. (The Makefile is then edited to change all references to ``makefile''
  1083. into ``Makefile''.)
  1084. .sp 0.13i
  1085. A file called ``NOTES'' is also expected in any source directory, and
  1086. will be created if it does not exist.
  1087. This file contains short notes on what the programs in the directory
  1088. do, where and whom they came from (if known), when they were received,
  1089. and any other relevant information (such as if they work and actually
  1090. seem to be useful).
  1091. \fISavesrc\fR will create a basic NOTES entry for any program it deals
  1092. with if the user so desires.
  1093. The NOTES file is intended to be manipulated by a another program,
  1094. \fInote(1L)\fR, but since it is a ordinary ASCII file, it may be
  1095. attacked with any of the normal Unix utilities.
  1096. .sp 0.13i
  1097. The \fBdestination\fR names that \fIsavesrc\fR knows about are ones ending
  1098. in ``.?'', ``.fix'', ``.bug'', ``.patch'', ``.[1-8]'', and ``READ*'',
  1099. which are assumed to be source (C, YACC, lex, etc.) or header files,
  1100. bug fixes, manual pages, or README's.
  1101. (The ``.bug'', ``.fix'', and ``.patch'' suffixes exist to
  1102. allow convenient saving of bugs, patches, and fixes in a general sources
  1103. directory.)
  1104. Any other destination name is assumed to be a sub-directory under the main
  1105. sources directory, unless it is a full pathname.
  1106. .sp 0.2i
  1107. \fBSingle Source Programs, Header Files, and README's\fR
  1108. .sp 0.13i
  1109. \fISavesrc\fR tries to put single-file sources, header files, and README's
  1110. in the main sources directory.
  1111. If the destination name already exists, the user is given the choice of
  1112. overwriting it, appending to it, or specifying a new destination
  1113. (which is also checked).
  1114. The user is given a chance to edit the file or start up a shell
  1115. for further twiddling.
  1116. At this point \fIsavesrc\fR will terminate for header files and README's;  for
  1117. bugs, fixes, and patches, the user will be offered a shell before \fIsavesrc\fR
  1118. terminates.
  1119. .sp 0.2i
  1120. \fBSource Programs\fR
  1121. .sp 0.13i
  1122. For sources, the user is prompted for a half-line description of the
  1123. program, and a check is made to see if a Makefile entry already exists
  1124. for the program.
  1125. If not, and the user indicates he wants one, a default entry of the form:
  1126. .sp 0.13i
  1127. .nf
  1128. .in +0.7i
  1129. program:    program.o
  1130.     cc $(CFLAGS) program.o -o program
  1131. .fi
  1132. .in -0.7i
  1133. .sp 0.13i
  1134. is presented for his approval.
  1135. If he approves, this is appended to the Makefile.
  1136. If not, he is prompted for the complete Makefile entry.
  1137. In either case, the Makefile entry is preceded by a blank line and the
  1138. half-line program description as a comment.
  1139. The user is then given a chance to edit the Makefile.
  1140. .sp 0.13i
  1141. Next, the user is prompted for adding a basic NOTES entry, asked if the
  1142. program should be compiled, offered a shell to twiddle or test it, and
  1143. finally prompted for any further NOTES entries (\fIe.g.\fR, ``Compiled
  1144. OK but removed /unix when I ran it.
  1145. Must remember to sue author.'').
  1146. If the program came from a netnews article, the basic NOTES entry will
  1147. include the author and the posting path, if possible, as well as the
  1148. program name, the current date, and the half-line program description.
  1149. (In compiling the program, the command used is in effect ``make \(gabasename
  1150. destination .c\(ga''.)
  1151. .sp 0.2i
  1152. \fBManual Pages\fR
  1153. .sp 0.13i
  1154. Manual pages are placed in the main sources directory, first checking
  1155. that they will not overwrite a previous copy unless the user wishes to.
  1156. The user may then edit them.
  1157. For manual page sources (as opposed to pre-formatted pages), the user is asked
  1158. if he wishes to move them to the appropriate section of the manual
  1159. source directory, and if he wants a formatted copy made and filed.
  1160. If a formatted copy is made, it will also be shown on the terminal.
  1161. If the correct directory for the source or formatted page does not exist,
  1162. \fIsavesrc\fR attempts to create it.
  1163. For pre-formatted manual pages, the user is given the option of moving
  1164. them to the appropriate directory.
  1165. (As yet there is no utility to generate source from formatted manual
  1166. pages, but stay tuned...)
  1167. .sp 0.2i
  1168. \fBLarge (Multi-File) C Programs\fR
  1169. .sp 0.13i
  1170. When \fIsavesrc\fR cannot recognize the destination name as a single source
  1171. program, a manual page, a header file, a bug, fix, or patch, or a README,
  1172. it looks for a subdirectory
  1173. of the main sources directory with that name (unless the destination
  1174. is a full pathname, in which case it looks for that directory).
  1175. If the directory exists, the user is given the option of working in
  1176. that directory, or of specifying a different directory (which is also
  1177. checked).
  1178. .sp 0.13i
  1179. Once the working directory has been found and made the current directory,
  1180. the user is prompted for a half-line description of what the program
  1181. does.
  1182. If no description is wanted (\fIe.g.\fR, a new version is being saved),
  1183. just hitting \s8RETURN\s10 will have no ill effects.
  1184. .sp 0.13i
  1185. The user is asked if he wants to use \fIunshar(1L)\fR to unpack the sources.
  1186. If he opts for \fIunshar\fR, he is asked if it worked;  if not, a shell is
  1187. started automatically.
  1188. If he does not want to use \fIunshar\fR, he may edit the sources or
  1189. start a shell, is then shown a listing of the directory, and finally prompted
  1190. for a name to copy the temporary file where \fIsavesrc\fR first puts the sources
  1191. (``/tmp/newsrc$$'') to.
  1192. .sp 0.13i
  1193. Once the files are unpacked, \fIsavesrc\fR looks for a README or READ_ME
  1194. file, and offers to show it to the user.
  1195. If it cannot find one, it asks if the user wants to edit one.
  1196. .sp 0.13i
  1197. Next, \fIsavesrc\fR deals with any manual pages just as described above,
  1198. except that they are copied to the main manual page directories, rather
  1199. than moved there.
  1200. The rationale for this is that while one does not usually want lots of
  1201. manual pages cluttering up a general source directory, for larger
  1202. software packages which merit directories of their own it is best
  1203. to keep the original distribution together, as this simplifies
  1204. packaging for re-distribution.
  1205. The option of copying the manual pages to a central location is given
  1206. because it is also convenient to have a canonical collection of
  1207. manual pages.
  1208. .sp 0.13i
  1209. The question of a Makefile comes next.
  1210. \fISavesrc\fR turns any ``makefile'' into ``Makefile'' as mentioned
  1211. before.
  1212. If no Makefile is present, the user is asked if one is hiding somewhere
  1213. (\fIe.g.\fR, ``Makefile.bsd''), and this is copied to Makefile.
  1214. If no Makefile at all can be found, a basic Makefile is generated
  1215. automatically, using the one-line program description and simple-mindedly
  1216. assuming that all the .c files are compiled up together.
  1217. For example, suppose we have a new game of pacman, being placed
  1218. in a directory called ``pacman''.
  1219. The one-line description we have given it is ``a new, improved version
  1220. of pacman'', and we have unshared four files, \fIpac.c\fR, \fIpac.h\fR,
  1221. \fIscore.c\fR, and \fItty.c\fR.
  1222. The default Makefile will contain:
  1223. .sp 0.13i
  1224. .ne 14
  1225. .in +0.7i
  1226. .nf
  1227. .ta 0.4i 0.8i
  1228. # pacman -- a new, improved version of pacman
  1229. .sp 0.2i
  1230. CFILES =        pac.c score.c tty.c
  1231. .sp 0.13i
  1232. OFILES =        pac.o score.o tty.o
  1233. .sp 0.13i
  1234. CFLAGS =        -O
  1235. .sp 0.13i
  1236. pacman:     $(OFILES)
  1237.     cc $(CFLAGS) $(OFILES) -o pacman
  1238. .sp 0.13i
  1239. clean:
  1240.     rm -f *.o
  1241. .sp 0.2i
  1242. .fi
  1243. .in -0.7i
  1244. (Note that CFLAGS may be set in the environment or adjusted by editing
  1245. \fIsavesrc\fR;  its default is ``-O''.)
  1246. No attempts to include libraries are made;  the above example would
  1247. almost certainly need `` -ltermcap'' added to the ``cc'' line.
  1248. .sp 0.13i
  1249. The user is next offered a chance to edit the Makefile (which it is
  1250. sensible to accept).
  1251. .sp 0.13i
  1252. Finally, as for a single C program, the user is prompted for adding a
  1253. basic NOTES entry, asked if the program should be compiled (using just
  1254. ``make''), offered a shell to twiddle or test it, and prompted for any
  1255. further NOTES entries.
  1256. If the program came from a netnews article, the basic NOTES entry will
  1257. include the author and the posting path, if possible, as well as the
  1258. program name, the current date, and the half-line program description.
  1259. .SH EXAMPLES
  1260. XFrom \fIrn(1)\fR, ``| savesrc pacman'' will unpack a (presumably shar-ed)
  1261. article into $HOME/src/pacman, and prompt the user for the steps
  1262. necessary to compile and test it.
  1263. .sp 0.13i
  1264. ``savesrc /usr/joe/mung.c mungstuff'' will save the file ``mungstuff''
  1265. as ``/usr/joe/mung.c'', and prompt for compiling etc.
  1266. .SH ENVIRONMENT VARIABLES
  1267. .ta 1i 3i
  1268. .nf
  1269. .sp 0.13i
  1270. \fBName    Default    Description\fR
  1271. .sp 0.13i
  1272. VISUAL    /usr/bin/vi    Used to edit files
  1273. EDITOR    none    Used if VISUAL is not set
  1274. SHELL    /bin/sh    Used to start a shell
  1275. PAGER    /usr/local/bin/more    Used to page output
  1276. srcdir    $HOME/src    Main sources directory
  1277. mandir    $HOME/man    Main manual page source directory
  1278. catdir    $HOME/man    Main pre-formatted manual page directory
  1279. CFLAGS    -O    Compiler options for Makefile entries
  1280. .fi
  1281. .SH FILES
  1282. /tmp/newsrc$$
  1283. .SH SEE ALSO
  1284. \fInote(1L), shar(1L), unshar(1L), rn(1), readnews(1)\fR
  1285. .SH AUTHOR
  1286. Written by Christine Robertson, 1986.
  1287. .SH WARNINGS
  1288. \fISavesrc\fR assumes that `` [ '' exists as a synonym for \fItest(1)\fR.
  1289. If you don't have it, either link \fItest\fR to it, or replace the
  1290. `` [ ... ] '' constructs with ``test ...''.
  1291. .sp 0.13i
  1292. The utilities \fIunshar(1L)\fR and \fInote(1L)\fR are also assumed;  they
  1293. may be replaced with ``sh'' and ``cat >> NOTES'', respectively.
  1294. .sp 0.13i
  1295. If your shell does not support # as the comment character, remove all
  1296. the # comments.
  1297. .sp 0.13i
  1298. This program was written to organize sources in the way the author likes
  1299. them.
  1300. There is no guarantee \fIyou\fR will like this too.
  1301. .SH BUGS
  1302. Please send all bug reports to {linus, ihnp4, decvax}!utzoo!toram!chris.
  1303. SHAR_EOF
  1304. if test 12044 -ne "`wc -c < 'savesrc.1'`"
  1305. then
  1306.     echo shar: error transmitting "'savesrc.1'" '(should have been 12044 characters)'
  1307. fi
  1308. fi
  1309. exit 0
  1310. #    End of shell archive
  1311.